home *** CD-ROM | disk | FTP | other *** search
- Path: newsserver.rdcs.kodak.com!fietze
- From: fietze@kagcpd01.ag01.kodak.COM (Roman Fietze)
- Newsgroups: comp.lang.c++
- Subject: Re: Bug or Feature? const int variables do not export in gcc 2.7.0
- Followup-To: comp.lang.c++
- Date: 12 Feb 1996 07:41:02 GMT
- Organization: Eastman Kodak Company
- Message-ID: <FIETZE.96Feb12084102@kagcpd01.ag01.kodak.COM>
- References: <4fdlee$bpf@netlab.cs.rpi.edu>
- NNTP-Posting-Host: kagcpd01.ag01.kodak.com
- In-reply-to: ivo.welch@AGSM.UCLA.EDU's message of 8 Feb 1996 20:11:58 -0000
-
- In article <4fdlee$bpf@netlab.cs.rpi.edu> ivo.welch@AGSM.UCLA.EDU (Ivo Welch) writes:
-
- On a NextStep/FIP system w/ gcc 2.7.0:
-
- File try2.cc:
- int ex1=2;
-
- File try1.cc:
- extern "C" {
- #include <stdio.h>
- }
-
- int main() {
- extern int ex1; printf("Extern = %d\n", ex1); return 0; }
-
- works, but if I replace "int" with "const int" in both situations, the
- linker complains that ex1 is not defined. NOTE that it works with "const"
- in gcc if instead of C++ I switch to plain C.
-
- It looks funny, but you have to say:
-
- extern const int ex1 = 2; // where you define it
-
- and
-
- extern const int ex1; // where else you need it.
-
- const's are local to theit translation units by default, you have to
- declare them extern if you need them outside a module (see
- Ellis/Stroustrup, The Annotated C++ Ref. Manula, 3.3 Program and
- Linkage).
-
- Roman
- --
- Roman Fietze (Mail Code 5023) Kodak AG Stuttgart/Germany
- fietze@kagcpd01.ag01.kodak.COM fietze@kodak.COM
-